<?php
/*
 * @Description: 会员疗程卡
 * @Author: QinTianyu
 * @Date: 2020-04-24 11:18:02
 * @LastEditors: QinTianyu
 * @LastEditTime: 2020-05-09 13:42:19
 */

namespace app\shouyin\model;

use think\Model;
use think\Loader;
use app\user\model\User as UserModel;
use app\shop\model\Shop as ShopModel;
use app\finance\model\Account as AccountModel;
use app\shouyin\model\Course as CourseModel;
use app\system\model\systemUser as systemUserModel;
use app\shouyin\model\UserBalanceLog as UserBalanceLogModel;
use app\shouyin\model\UserCardLog as UserCardLogModel;
class UserCard extends Model
{

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    public function getAccountIdTextAttr($value,$data)
    { 

        $account_arr = AccountModel::where('status',1)->column('id,name');
        $account_arr[-2] = "赠送";
        $account_arr[-5] = "会员卡赠送";

        return $account_arr[$value];
    }
    public function getAdviserIdTextAttr($value,$data)
    {
        return $this->admins($data['adviser_id']);
    }
    public function getTechnicianIdTextAttr($value,$data)
    {
        return $this->admins($data['technician_id']);
    }
    public function getTechnicianTextAttr($value,$data)
    {
        $name = systemUserModel::where('id','in', $value)->column('nick');
        return implode(',', $name);
    }
    public function getCashierIdTextAttr($value,$data)
    {
        return $this->admins($data['cashier_id']);
    }
    public function getFinanceIdTextAttr($value,$data)
    {
        return $this->admins($data['finance_id']);
    }
    public function getUserIdTextAttr($value,$data)
    {
        $user = UserModel::get($data['user_id']);
        return $user['nick'];
    }
    public function getCourseIdTextAttr($value,$data)
    {
        $user = CourseModel::get($data['course_id']);
        return $user['name'];
    }
    public function admins($id)
    {
        $admins = systemUserModel::where('id', $id)->value('nick');
        return $admins;
    }

    public function getShopIdTextAttr($value,$data)
    {
        $shop = ShopModel::get($data['shop_id']);
        // halt($shop);
        return $shop['name'];
    }

}